import { createPersistStore } from './index'

// 编辑器主题类型
export type EditorThemeType = 'light' | 'dark' | 'system';

// 字体大小
export type FontSizeType = 'small' | 'medium' | 'large';

// 应用主题
export type AppThemeType = 'light' | 'dark' | 'system';

// 编辑器设置接口
export interface EditorSettings {
  theme: EditorThemeType;
  fontSize: FontSizeType;
  fontFamily: string;
  lineHeight: number;
  paragraphSpacing: number;
  showWordCount: boolean;
  focusMode: boolean;
}

export interface SettingsState {
  // 应用设置
  appTheme: AppThemeType;
  sidebarWidth: number;
  rightSidebarWidth: number;
  showLineNumbers: boolean;
  
  // 编辑器设置
  editorTheme: EditorThemeType;
  fontSize: FontSizeType;
  spellCheck: boolean;
  autoSave: boolean;
  autoSaveInterval: number; // 秒
  editorSettings: EditorSettings;
  
  // AI助手设置
  aiAssistantPanelWidth: number;
  aiModel: string;
  temperature: number;
  
  // 操作函数
  updateSettings: (updates: Partial<Omit<SettingsState, 'updateSettings' | 'resetSettings'>>) => void;
  resetSettings: () => void;
}

// 默认设置
const DEFAULT_SETTINGS: Omit<SettingsState, 'updateSettings' | 'resetSettings'> = {
  // 应用设置
  appTheme: 'system',
  sidebarWidth: 250,
  rightSidebarWidth: 300,
  showLineNumbers: true,
  
  // 编辑器设置
  editorTheme: 'system',
  fontSize: 'medium',
  spellCheck: true,
  autoSave: true,
  autoSaveInterval: 30,
  editorSettings: {
    theme: 'system',
    fontSize: 'medium',
    fontFamily: '',
    lineHeight: 1.5,
    paragraphSpacing: 1.5,
    showWordCount: true,
    focusMode: false
  },
  
  // AI助手设置
  aiAssistantPanelWidth: 380,
  aiModel: 'gpt-4',
  temperature: 0.7
}

export const useSettingsStore = createPersistStore<SettingsState>(
  'settings',
  DEFAULT_SETTINGS as any,
  (set) => ({
    ...DEFAULT_SETTINGS,
    
    updateSettings: (updates) => {
      set(state => ({
        ...state,
        ...updates
      }));
    },
    
    resetSettings: () => {
      set(DEFAULT_SETTINGS);
    }
  })
); 